package com.aoxin.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import com.aoxin.util.redis.BaseRedis;

@Component
public class RedisUtil implements ApplicationContextAware {

	private static ApplicationContext applicationContext;

	@Override
	public void setApplicationContext(ApplicationContext arg0) throws BeansException {
		RedisUtil.applicationContext = arg0;
	}

	private static BaseRedis getBaseRedis() {
		return RedisUtil.applicationContext.getBean(BaseRedis.class);
	}

	public static void set(String key, Object value) {
		getBaseRedis().setObj(key, value);
	}

	public static void set(String key, Object value, long time) {
		getBaseRedis().setObj(key, value, time);
	}

	public static Object get(String key) {
		return getBaseRedis().getObj(key);
	}

	public static void del(String key) {
		getBaseRedis().delObj(key);
	}
}
